package org.gd.hellojavacore.currency;

import java.util.Currency;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Gorhover
 * @since 1.0
 */
public final class CurrencyMap {

    private static Map<Integer, Currency> currencyMap = null;

    private CurrencyMap() {
    }

    public static Map<Integer, Currency> getCurrencyMap() {
        if(currencyMap == null || currencyMap.isEmpty()) {
            synchronized (CurrencyMap.class) {
                if(currencyMap == null || currencyMap.isEmpty()) {
                    currencyMap = new HashMap<>();
                    for(Currency currency: Currency.getAvailableCurrencies()) {
                        currencyMap.put(currency.getNumericCode(), currency);
                    }
                }
            }
        }
        return currencyMap;
    }

    public static Currency getCurrencyByNumericCode(int numericCode) {
        return getCurrencyMap().get(numericCode);
    }
}
